<template>
  <a-popconfirm
    :title="title"
    @confirm="handleSubmit(roleIds)"
    okText="是"
    cancelText="否"
  >
    <a href="#">删除</a>
  </a-popconfirm>
</template>

<script>
import { removeRole } from '@/api/system/role'

export default {
  props: {
    roleIds: {
      type: String
    }
  },
  data () {
    return {
      title: '确定要删除这' + this.roleIds.split(',').length + '条记录吗？'
    }
  },
  watch: {
    roleIds: function (val) {
      this.title = '确定要删除这' + val.split(',').length + '条记录吗？'
    }
  },
  methods: {
    handleSubmit (roleIds) {
      removeRole({ 'roleIds': roleIds })
        .then(res => {
          if (res.message !== 'error') {
            this.$emit('ok')
          } else {
            this.$message.error('操作失败！')
          }
        })
    }
  }
}
</script>
